package programmingChallenges.chap2;

import java.io.*;
import java.util.*;

class Main implements Runnable{
    static String ReadLn(int maxLength){  // utility function to read from stdin,
                                          // Provided by Programming-challenges, edit for style only
        byte line[] = new byte [maxLength];
        int length = 0;
        int input = -1;
        try{
            while (length < maxLength){//Read untill maxlength
                input = System.in.read();
                if ((input < 0) || (input == '\n')) break; //or untill end of line ninput
                line [length++] += input;
            }

            if ((input < 0) && (length == 0)) return null;  // eof
            return new String(line, 0, length);
        }catch (IOException e){
            return null;
        }
    }

    public static void main(String args[])  // entry point from OS
    {
        Main myWork = new Main();  // Construct the bootloader
        myWork.run();            // execute
    }

    public void run() {
        new myStuff().run();
    }
}
class myStuff implements Runnable{
    public void run(){
    	
    	/*Integer map[][] = {
				{-1,  0, 0, 0, 0},
				{ 0,  0, 0, 0, 0},
				{ 0, -1, 0, -1, 0},
				{ 0,  0, 0, 0, 0},
				{ -1,  0, 0, -1, 0}
		};*/
    	
    	String str = Main.ReadLn(100);
    	String mapSize[] = str.split(" ");
    	int width = Integer.parseInt(mapSize[0]);
    	int height = Integer.parseInt(mapSize[1].replace("\r", ""));
    	Integer map[][] = new Integer[width][height];
    	
    	String line = "";
    	for (int h=0; h<height; h++) {
    		line = Main.ReadLn(100);
    		for (int w=0; w<width; w++) {
    			if (String.valueOf(line.charAt(w)).equals("*"))
    				map[h][w] = -1;
    			else
    				map[h][w] = 0;
    		}
    	}
    	
		for (int i=0; i<map.length; i++) {
			
			for (int k=0; k<map[i].length; k++) {
				
				if (map[i][k] == -1) {
					
					// Check Edge
					if (i > 0 && map[i-1][k] != -1)
						map[i-1][k]++;
					if (k > 0 && map[i][k-1] != -1)
						map[i][k-1]++;
					if (k < 3 && map[i][k+1] != -1)
						map[i][k+1]++;
					if (i < 3 && map[i+1][k] != -1)
						map[i+1][k]++;
				}
				
			}
			
		}
		
		// Print Map
		for (int i=0; i<map.length; i++) {
			
			for (int k=0; k<map[i].length; k++) {
				System.out.print((map[i][k] == -1 ? "*" : map[i][k]) + " ");
			}
			System.out.println();
		}
    }
}